home *** CD-ROM | disk | FTP | other *** search
- //****************************************************************************
- // File: progress.c
- //
- // Purpose: example DLL file to display a custom progress bar
- //
- // Functions: LibMain, Update
- //
- //
- // Programmer: John McMillan
- // Update to Win32: Gary Chirhart
- //
- //****************************************************************************
-
- #include <windows.h>
- #include "resource.h"
- #include "..\wisedll.h"
-
- #define PROGRESS_BAR_TYPE_INIT 0
- #define PROGRESS_BAR_TYPE_SHOW 1
- #define PROGRESS_BAR_TYPE_HIDE 2
- #define PROGRESS_BAR_TYPE_DONE 3
-
- #ifdef WIN32
- //#define huge
- #define __export __declspec( dllexport )
- #define __loadds
- #endif
-
- HINSTANCE hDllInst; // The instance of this DLL
- HWND hProgressDlg; // The Progress dialog window handle
- HFONT hLightFont; // A non-bold font for the dialog text
- int iWndPosition; // A number from 0 to 8 indicating the postition of the progress dialog
- int iTotalPercent; // The percentage (times 10) of the total installation
- int iFilePercent; // The percentage (times 10) of the current file
- BOOL bCanceled; // True if the user pressed the cancel button
- BOOL bHidden; // The progress bar dialog is hidden
- BOOL bCentered; // Indicates if the dialog has been centered
- POINT ptTotalStart,ptTotalEnd; // The upper left and lower right points of total progress bar
- POINT ptFileStart,ptFileEnd; // The upper left and lower right points of total progress bar
-
- BOOL __export CALLBACK ProgressDlg(HWND, UINT, WPARAM, LPARAM);
- void CenterWindow(HWND hWnd);
- void GetEndPoints(HWND hDlg,UINT uID,POINT* pStart,POINT* pEnd);
- void DisplayBar(HDC hdc,POINT* ptStart,POINT* ptEnd,int iPercent);
- void SetLightFont(HWND hWnd);
- BOOL CALLBACK __loadds EnumChildCallback(HWND hWnd,LPARAM lParam);
-
- //***********************************************************************
- // Function: LibMain
- //
- // Purpose: C function called from DLL entry point.
- //
- // Parameters: HINSTANCE hInst; DLL instance handle
- // WORD wSeg; DLL data segment selector
- // WORD cbHeapSize; DLL initial heap size in bytes
- // LPSTR lpszCmdLine; DLL command line
- //
- // Returns: 1 is success, 0 fail DLL load
- //
- // Comments:
- //
- // History: Date Author Reason
- //
- //****************************************************************************
- #ifndef WIN32
- int CALLBACK LibMain(HINSTANCE hInst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
- {
- hDllInst = hInst;
- return(1);
- }
- #endif
- #ifdef WIN32
- BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,LPVOID lpvReserved)
- {
- hDllInst = hinstDLL;
- return TRUE;
- }
- #endif
- //***********************************************************************
- // Function: Update
- //
- // Purpose: Called to update the progress bar
- //
- // Parameters:
- //
- //
- // Comments:
- //
- // History: Date Author Reason
- //
- //****************************************************************************
-
- HWND __export CALLBACK Update(int iType,int iPosition,LPDLLCALLPARAMS lpDllParams,char const* szDescr,int iPerInstall,int iPerFile)
- {
- RECT rc;
-
- switch (iType) {
- case PROGRESS_BAR_TYPE_INIT:
- bHidden = TRUE;
- return hProgressDlg = CreateDialog(hDllInst,MAKEINTRESOURCE(IDD_PROGRESS_DLG),(HWND)lpDllParams->hWnd,ProgressDlg);
- break;
- case PROGRESS_BAR_TYPE_SHOW:
- if (bCanceled) {
- bCanceled = FALSE; // Turn this off in case user chooses to continue
- return hProgressDlg;
- }
- if ((szDescr == NULL) && bHidden) return NULL;
- iWndPosition = iPosition;
- if (!bCentered) {
- CenterWindow(hProgressDlg);
- bCentered = TRUE;
- }
- if (bHidden) {
- EnableWindow(hProgressDlg,TRUE);
- ShowWindow(hProgressDlg,SW_SHOW);
- bHidden = FALSE;
- }
- if (szDescr != NULL) SetDlgItemText(hProgressDlg,IDC_STATIC_TEXT,szDescr);
- iTotalPercent = iPerInstall;
- iFilePercent = iPerFile;
- rc.top = ptTotalStart.y - 1;
- rc.bottom = ptTotalEnd.y + 1;
- rc.left = ptTotalStart.x - 1;
- rc.right = ptTotalEnd.x + 1;
- InvalidateRect(hProgressDlg,&rc,FALSE);
- rc.top = ptFileStart.y - 1;
- rc.bottom = ptFileEnd.y + 1;
- rc.left = ptFileStart.x - 1;
- rc.right = ptFileEnd.x + 1;
- InvalidateRect(hProgressDlg,&rc,FALSE);
- break;
- case PROGRESS_BAR_TYPE_HIDE:
- EnableWindow(hProgressDlg,FALSE);
- ShowWindow(hProgressDlg,SW_HIDE);
- bHidden = TRUE;
- break;
- case PROGRESS_BAR_TYPE_DONE:
- if (hLightFont != NULL) DeleteObject(hLightFont);
- DestroyWindow(hProgressDlg);
- break;
- }
- return NULL;
- }
-
- BOOL __export CALLBACK ProgressDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
-
- switch (message) {
- case WM_INITDIALOG:
- SetLightFont(hDlg);
- GetEndPoints(hDlg,IDC_STATIC_TOTAL,&ptTotalStart,&ptTotalEnd);
- GetEndPoints(hDlg,IDC_STATIC_FILE,&ptFileStart,&ptFileEnd);
- return TRUE;
- case WM_PAINT:
- hdc = BeginPaint(hDlg,&ps);
- DisplayBar(hdc,&ptTotalStart,&ptTotalEnd,iTotalPercent);
- DisplayBar(hdc,&ptFileStart,&ptFileEnd,iFilePercent);
- EndPaint(hDlg,&ps);
- break;
- case WM_COMMAND:
- bCanceled = TRUE;
- break;
- }
- return FALSE;
- }
-
- void CenterWindow(HWND hWnd)
- {
- int i,j,x,y,iScreenX,iScreenY;
- RECT rc;
- HDC hDC;
-
- GetWindowRect(hWnd,&rc);
- i = rc.right - rc.left;
- j = rc.bottom - rc.top;
- hDC = GetDC(NULL);
- iScreenX = GetDeviceCaps(hDC,HORZRES);
- iScreenY = GetDeviceCaps(hDC,VERTRES);
- x = (((((iWndPosition & 0xf) % 3) + 1) * iScreenX) / 4) - (i / 2);
- y = (((((iWndPosition & 0xf) / 3) + 1) * iScreenY) / 4) - (j / 2);
- if ((x + i) > iScreenX) x = iScreenX - i;
- if ((y + j) > iScreenY) y = iScreenY - j;
- if (x < 0) x = 0;
- if (y < 0) y = 0;
- ReleaseDC(NULL,hDC);
- MoveWindow(hWnd,x,y,i,j,FALSE);
- }
-
-
- void GetEndPoints(HWND hDlg,UINT uID,POINT* ptStart,POINT* ptEnd)
- {
- HWND hBoxWnd;
- RECT rc;
-
- hBoxWnd = GetDlgItem(hDlg,uID);
- if (hBoxWnd != NULL) {
- GetWindowRect(hBoxWnd,&rc);
- ptStart->x = rc.left + 1;
- ptStart->y = rc.top + 1;
- ScreenToClient(hDlg,ptStart);
- ptEnd->x = rc.right - 1;
- ptEnd->y = rc.bottom - 1;
- ScreenToClient(hDlg,ptEnd);
- }
- }
-
- void DisplayBar(HDC hdc,POINT* ptStart,POINT* ptEnd,int iPercent)
- {
- SIZE sSize;
- char ach[8];
- RECT rc,rc1;
- WORD wGomerX,wWidth,wHeight;
- int iCurrPercent;
-
- wWidth = (WORD)(ptEnd->x - ptStart->x);
- wHeight = (WORD)(ptEnd->y - ptStart->y);
- rc.left = ptStart->x;
- rc.right = ptStart->x + (WORD)(((DWORD)iPercent * (DWORD)wWidth) / (DWORD)1000);
- rc.top = ptStart->y;
- rc.bottom = ptEnd->y;
- iCurrPercent = (iPercent + 5) / 10;
- wsprintf(ach,"%3d%%",iCurrPercent);
- GetTextExtentPoint(hdc,ach,wGomerX = lstrlen(ach),&sSize);
- SetBkColor(hdc,RGB(0,0,127));
- SetTextColor(hdc,RGB(192,192,192));
- ExtTextOut(hdc, (wWidth - sSize.cx) / 2 + ptStart->x,
- (wHeight - sSize.cy) / 2 + ptStart->y,
- ETO_OPAQUE | ETO_CLIPPED, &rc, ach, wGomerX, NULL);
- SetBkColor(hdc,RGB(192,192,192));
- SetTextColor(hdc,RGB(0,0,127));
- rc1 = rc;
- rc1.left = rc.right + 1;
- rc1.right = ptEnd->x;
- ExtTextOut(hdc, (wWidth - sSize.cx) / 2 + ptStart->x,
- (wHeight - sSize.cy) / 2 + ptStart->y,
- ETO_OPAQUE | ETO_CLIPPED, &rc1, ach, wGomerX, NULL);
- }
-
- void SetLightFont(HWND hWnd)
- {
- HFONT hDialogFont;
- LOGFONT dlgFont;
-
- if (hLightFont == NULL) {
- hLightFont = NULL;
- if ((hDialogFont = (HFONT) SendMessage(hWnd,WM_GETFONT,0,0)) != NULL) {
- if (GetObject(hDialogFont,sizeof(dlgFont),&dlgFont)) {
- dlgFont.lfWeight = FW_LIGHT;
- hLightFont = CreateFontIndirect(&dlgFont);
- }
- }
- }
- if (hLightFont != NULL) EnumChildWindows(hWnd,EnumChildCallback,(LPARAM)hLightFont);
- }
-
- BOOL CALLBACK __loadds EnumChildCallback(HWND hWnd,LPARAM lParam)
- {
- SendMessage(hWnd,WM_SETFONT,(WPARAM)lParam,0L);
- return TRUE;
- }
-